<?php

Yii::import('application.modules.setting.models.Setting');

class ContactController extends Controller {

    /**
     * Lists all models.
     */
    public $layout = '//layouts/column2';

    public function init() {
        Yii::app()->theme = 'home';
    }

    public function actionContact() {
        $contact = Setting::model()->findByAttributes(array('key' => 'contact'));
        $model = new ContactForm;
        if (isset($_POST['ContactForm'])) {
            $model->attributes = $_POST['ContactForm'];
            if ($model->validate()) {
                $headers = "From: {$model->email}\r\nReply-To: {$model->email}";
                mail(Yii::app()->params['adminEmail'], $model->subject, $model->body, $model->phone, $headers);
                Yii::app()->user->setFlash('contact', 'Thank you for contacting us. We will respond to you as soon as possible.');
                $this->refresh();
            }
        }
        $this->render('contact', array('model' => $model, 'contact' => $contact));
    }

}